﻿//大图轮播
function FocusImg(bigDiv, smallDiv, titleDiv, imgW, imgH, imgList, sTime, introDiv)
{
    var $=function (obj){return document.getElementById(obj);}
    this.bigDiv=bigDiv;this.smallDiv=smallDiv,this.imgW=imgW;this.imgH=imgH;
    this.imgList=[];
    this.sTime=sTime;
    this.titleDiv=titleDiv;
    this.introDiv=introDiv;
    var scrollDiv;
    var smallImgList=[];
    var imgHeight,_bigDiv;
    var timer,autoTimer;
    var ctitle;
    var t=this;
    var cintro;
    this.curId=0;
    var smallPicArr=[];
    var mypic=document.createElement("img");
    var mypicLink=document.createElement("a");
    this.init=function()//初始化
    {						
        mypic.width=this.imgW;
        mypic.height=this.imgH;
        imgHeight=this.imgH;
        _bigDiv=this.bigDiv;
        _titleDiv=this.titleDiv;
        _introDiv=this.introDiv;
        _imgList=this.imgList;
        scrollDiv=document.createElement("div");
        mypicLink.target="_blank";
        mypicLink.appendChild(mypic);
        scrollDiv.appendChild(mypicLink);

        for ( var i = 0; i < this.imgList.length ; i++ )
        {

            //创建小图区域
            var slspan=document.createElement("div");
            slspan.className="small_div";
            var slimglink=document.createElement("a");
            slimglink.target="_blank";
            slimglink.href=this.imgList[i].url;
            var slimg=document.createElement("img");
            slimg.src=this.imgList[i].bigimg;
            slimglink.appendChild(slimg);
            slimglink.innerHTML += this.imgList[i].intro;
            slspan.appendChild(slimglink);
            smallPicArr.push(slspan);
            (function(){
                var itemid=i;				
                slspan.onmouseover=function()
                {
                    t.doPic(itemid);
                    t.curId=itemid;
                    clearInterval(autoTimer);
                    t.autoPlay();
                }

            })();
            $(this.smallDiv).appendChild(slspan);

        }
        $(this.bigDiv).style.width=this.imgW+"px";
        $(this.bigDiv).style.height=this.imgH+"px";
        $(this.bigDiv).style.overflow="hidden";
        $(this.bigDiv).appendChild(scrollDiv);
        this.doPic(0);

    };
    this.doPic=function(id)
    {		
        try{clearTimeout(timer)}catch(e){};
        $(this.titleDiv).innerHTML=this.imgList[id].title;
        if ($(this.introDiv) && this.imgList[id].intro)
            $(this.introDiv).innerHTML=this.imgList[id].intro ;
        else if($(this.introDiv) || (!this.imgList[id].intro))
            $(this.introDiv).innerHTML="";
        //animate($(this.bigDiv).scrollTop,id * imgHeight);
        mypicLink.href=this.imgList[id].url;
        if (document.all)
        {
            mypic.filters.revealTrans.Transition=23;
            mypic.filters.revealTrans.apply();
            mypic.filters.revealTrans.play();
        }
        mypic.src=this.imgList[id].bigimg;
        //小图区域特效
        for (i = 0; i < smallPicArr.length ; i++ )
        {
            smallPicArr[i].className = smallPicArr[i].className.replace("selected" , "");
        }
        smallPicArr[id].className += " selected";
    }
    this.autoPlay=function()
    {
        autoTimer=setInterval(function(){
            t.curId++;
            if (t.curId >= t.imgList.length)
                t.curId = 0 ;
            t.doPic(t.curId);
        },this.sTime);
    }
    function callback(v)
    {
        $(_bigDiv).scrollTop = v;
    }
    function animate(beginV,endV)
    {
        x = endV - beginV;
        beginV += (x/4);
        if (Math.abs(beginV-endV) <= 1)
        {
            beginV = endV ;
            callback(endV);
        }
        else
        {			
            callback(beginV);
            timer=setTimeout(function(){animate( beginV  , endV)},10);
        }
    }
}

//大图轮播
(function (b, c) {
    var a = function (d, e) {
        this.$element = c(d);
        this.option = c.extend({}, c.fn.slideShow.defaults, e);
        this.timmer;
        this.$container = c(this.option.container);
        this.$control = c(this.option.control);
        this.$follow = this.$control.children(this.option.follower);
        this.$child = this.$container.children();
        this.follow_height = this.$control.find(":first-child").outerHeight();
        this.cur = 0; this.length = this.$child.length;
        this._init(); this._events()
    };
    a.prototype._init = function () {
        var d = this;
        d.$container.children().each(function (f, e) {
            var g = c(this);
            if (f === 0) {
                g.css({ opacity: 1 })
            } else {
                g.css({ display: "block", opacity: 0 })
            }
        });
        d.$control.children(d.option.trigger).each(function (f, e) {
            var g = c(this);
            g.data("slideindex", f)
        });
        d._start()
    };
    a.prototype.next = function () {
        var d = this, e;
        e = d.cur + 1 < d.length ? d.cur + 1 : 0; d.slideto(e)
    };
    a.prototype.prev = function () {
        var d = this, e;
        e = d.cur - 1 < 0 ? d.length - 1 : d.cur - 1; d.slideto(e)
    };
    a.prototype.slideto = function (e) {
        var f = this, g = f.cur, h = f.$child.eq(f.cur), d = f.$child.eq(e);
        if (g === e) {
            return
        } if (f.anim) {
            f.anim.stop(false, true)
        } d.css({ zIndex: 4, opacity: 1 });
        h.css({ zIndex: 5 });
        f.anim = h.animate({ opacity: 0 }, "fast", function () {
            h.css({ zIndex: 1 })
        });
        !!f.$follow && f.$follow.stop(true).animate({
            top: f.follow_height * e
        }, "fast", function () {
            f.$follow.css({
                top: f.follow_height * e
            })
        });
        f.cur = e
    };
    a.prototype._stop = function () {
        var d = this;
        clearTimeout(d.timmer)
    };
    a.prototype._start = function () {
        var d = this;
        d.timmer = setTimeout(function () {
            d.next();
            d._start()
        }, d.option.timeout)
    };
    a.prototype._events = function () {
        var e = this, d;
        e.$element.bind("mouseenter mouseleave", function (f) {
            if (f.type === "mouseenter") {
                e._stop()
            } else {
                if (f.type === "mouseleave") {
                    e._start()
                }
            }
        });
        c(e.option.control).delegate(e.option.trigger, "mouseenter", function (f) {
            var g = c(this);
            clearTimeout(d);
            d = setTimeout(function () {
                e.slideto(g.data("slideindex"))
            }, 100)
        })
    }; c
    .fn.slideShow = function (d) {
        return this.each(function () {
            var g = c(this), f = g.data("slideShow-obj"), e = typeof d === "object" && d;
            if (!f) {
                g.data("slideShow-obj", (f = new a(this, e)))
            }
        })
    };
    c.fn.slideShow.Constructor = a; c.fn.slideShow.defaults = {
        timeout: 4000,
        container: "#indexLeft",
        control: "#indexRight",
        trigger: "a",
        follower: "#hehe"
    }
})(window, jQuery);




$(function () {
  
   


    $("#indexSlide").slideShow({ container: "#indexLeft", control: "#indexRight", trigger: "a", follower: "#hehe" });

    //首页右侧选项卡
    $('#menu div').hover(function () {
        //获得当前被点击的元素索引值
        var Index = $(this).index();
        //给菜单添加选择样式
        $(this).addClass('active').siblings().removeClass('active');
        //显示对应的div
        $('.con').eq(Index).show().siblings('.con').hide();

    });

    //首页下方物品导航
    $(".ser_list").each(function () {
        var src;
        $(this).mouseover(function () {
            $(this).addClass("ser_list_active");
            src = $(this).find(".img_first").attr("src");
            var str = src.substring(0, src.length - 4)
            $(this).find(".img_first").attr("src", str + "_white.jpg");
            $(this).find(".img_more").attr("src", "./../Images/frontImages/more_red.jpg");
        }
        );
        $(this).mouseout(function () {
            if ($(this).hasClass("ser_list_active")) {
                $(this).removeClass("ser_list_active");
                $(this).find(".img_first").attr("src", src);
                $(this).find(".img_more").attr("src", "./../Images/frontImages/more.jpg");
            }
        });
    });

    //下拉菜单
    $(".toggle").slide({ type: "menu", titCell: ".tao_menu", targetCell: ".sub", delayTime: 0, triggerTime: 0, returnDefault: false });

    //发布信息 变色
    $(".publish").hover(
        function () {
            $(".publish img").attr("src", "./../Images/frontImages/publish2.gif")
        },
      function () {
          $(".publish img").attr("src", "../../Images/frontImages/publish.gif")
    });
});